//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef _RTL_NET_H__
#define _RTL_NET_H__

#define RTL8139CONNECT      0x01
#define RTL8139INITALIZE    0x02
#define RTL8139IOCTL        0x03
#define RTL8139WATCHDOG     0x04


struct if_data_ {
    /* generic interface information */
    u_char  ifi_type;       /* ethernet, tokenring, etc */
    u_char  ifi_physical;       /* e.g., AUI, Thinnet, 10base-T, etc */
    u_char  ifi_addrlen;        /* media address length */
    u_char  ifi_hdrlen;     /* media header length */
    u_char  ifi_recvquota;      /* polling quota for receive intrs */
    u_char  ifi_xmitquota;      /* polling quota for xmit intrs */
    u_long  ifi_mtu;        /* maximum transmission unit */
    u_long  ifi_metric;     /* routing metric (external only) */
    u_long  ifi_baudrate;       /* linespeed */
    /* volatile statistics */
    u_long  ifi_ipackets;       /* packets received on interface */
    u_long  ifi_ierrors;        /* input errors on interface */
    u_long  ifi_opackets;       /* packets sent on interface */
    u_long  ifi_oerrors;        /* output errors on interface */
    u_long  ifi_collisions;     /* collisions on csma interfaces */
    u_long  ifi_ibytes;         /* total number of octets received */
    u_long  ifi_obytes;         /* total number of octets sent */
    u_long  ifi_imcasts;        /* packets received via multicast */
    u_long  ifi_omcasts;        /* packets sent via multicast */
    u_long  ifi_iqdrops;        /* dropped on input, this interface */
    u_long  ifi_noproto;        /* destined for unsupported protocol */
    u_long  ifi_hwassist;       /* HW offload capabilities */
    u_long  ifi_unused;         /* XXX was ifi_xmittiming */
    struct  timeval ifi_lastchange; /* time of last administrative change */
};

#define IFF_UP      0x1     /* interface is up */
#define IFF_BROADCAST   0x2     /* broadcast address valid */
#define IFF_DEBUG   0x4     /* turn on debugging */
#define IFF_LOOPBACK    0x8     /* is a loopback net */
#define IFF_POINTOPOINT 0x10        /* interface is point-to-point link */
#define IFF_SMART   0x20        /* interface manages own routes */
#define IFF_RUNNING 0x40        /* resources allocated */
#define IFF_NOARP   0x80        /* no address resolution protocol */
#define IFF_PROMISC 0x100       /* receive all packets */
#define IFF_ALLMULTI    0x200       /* receive all multicast packets */
#define IFF_OACTIVE 0x400       /* transmission in progress */
#define IFF_SIMPLEX 0x800       /* can't hear own transmissions */
#define IFF_LINK0   0x1000      /* per link layer defined bit */
#define IFF_LINK1   0x2000      /* per link layer defined bit */
#define IFF_LINK2   0x4000      /* per link layer defined bit */
#define IFF_ALTPHYS IFF_LINK2   /* use alternate physical connection */
#define IFF_MULTICAST   0x8000      /* supports multicast */
#define IFF_POLLING 0x10000     /* Interface is in polling mode. */
#define IFF_PPROMISC    0x20000     /* user-requested promisc mode */
#define IFF_MONITOR 0x40000     /* user-requested monitor mode */


/*
 * Structure defining a queue for a network interface.
 */
struct  ifqueue_ {
    struct  mbuf *ifq_head;
    struct  mbuf *ifq_tail;
    int ifq_len;
    int ifq_maxlen;
    int ifq_drops;
    struct  mtx ifq_mtx;
    struct  mbuf *ifq_abandon;
};

#define BLK 220-4-4-4-80-28-4

struct ifnet_ {
    void    *v;                     /* procedure handles */
//    short   if_timer;               /* time 'til if_watchdog called */
    int   if_timer;               /* time 'til if_watchdog called */
    int     if_flags;               /* up/down, broadcast, etc. */
    struct  if_data_ if_data;
    struct  ifqueue_ if_snd;        /* output queue */
    int     sizeifnet;              //sizeof struct ifnet

    char    blank[BLK];             //append the other useless data items
};


#define if_mtu      if_data.ifi_mtu
#define if_type     if_data.ifi_type
#define if_physical if_data.ifi_physical
#define if_addrlen  if_data.ifi_addrlen
#define if_hdrlen   if_data.ifi_hdrlen
#define if_metric   if_data.ifi_metric
#define if_baudrate if_data.ifi_baudrate
#define if_hwassist if_data.ifi_hwassist
#define if_ipackets if_data.ifi_ipackets
#define if_ierrors  if_data.ifi_ierrors
#define if_opackets if_data.ifi_opackets
#define if_oerrors  if_data.ifi_oerrors
#define if_collisions   if_data.ifi_collisions
#define if_ibytes   if_data.ifi_ibytes
#define if_obytes   if_data.ifi_obytes
#define if_imcasts  if_data.ifi_imcasts
#define if_omcasts  if_data.ifi_omcasts
#define if_iqdrops  if_data.ifi_iqdrops
#define if_noproto  if_data.ifi_noproto
#define if_lastchange   if_data.ifi_lastchange
#define if_recvquota    if_data.ifi_recvquota
#define if_xmitquota    if_data.ifi_xmitquota
#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)

/* for compatibility with other BSDs */
#define if_addrlist if_addrhead
#define if_list     if_link

struct  arpcom_ {
    /*
     * The ifnet struct _must_ be at the head of this structure.
     */
    struct  ifnet_ ac_if;        /* network-visible interface */
    u_char  ac_enaddr[6];       /* ethernet hardware address */
    int     ac_multicnt;                 /* length of ac_multiaddrs list */
    struct  ether_multi *ac_multiaddrs;  /* list of ether multicast addrs */
};

typedef struct if_softc_ {
    struct arpcom_  arpcom;        /* interface info */
    void * rtl_handle;
}Rtl8139;



struct ioctlArg_t
{
    Rtl8139 	*ifnetaddr;
    UInt32     	cmd;
};



#endif //_RTL_NET_H__
